// pages/record/index.js
const Page = require('../../../utils/ald-stat.js').Page;
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    recordList:'',
    haveMore:true,
    page:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var object = {
      unionid: wx.getStorageSync('openid'),
      page: 1,
    }
    var signs = app.sort_ASCII(object)
    wx.request({
      url: app.globalData.new_url + '/weighing/Weighing/weight_list',
      data: {
        page: 1,
        unionid: wx.getStorageSync('openid'),
        sign:signs
      },
      method: 'POST',
      success: function (res) {
       console.log(res)
       if(res.data.code===200){
         that.setData({
           recordList: res.data.res
         })
         that.data.haveMore=res.data.more
       }
      }
    })
  },
  // 上拉触底事件，请求记录数据
  onReachBottom: function () {
    const that = this
    let page = that.data.page;
    if (that.data.haveMore) {
      // 请求下一页数据
      page++;
      that.data.page = page
      var obj = {
        unionid: wx.getStorageSync('openid'),
        page: page,
      }
      var sign = app.sort_ASCII(obj)
      wx.request({
        url: app.globalData.new_url + '/weighing/Weighing/weight_list',
        data: {
          page: page,
          unionid: wx.getStorageSync('openid'),
          sign:sign
        },
        method: 'POST',
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res)
          that.data.recordList = that.data.recordList.concat(res.data.res);
          that.setData({
            recordList: that.data.recordList,
          })
          that.data.haveMore = res.data.more
        }
      })
    } else {

    }
  },

})